Socket
Socket
Sign inDemoInstall

untyped

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

untyped

[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![Github Actions][github-actions-src]][github-actions-href] [![Codecov][codecov-src]][codecov-href] [![bundle][bundle-src]][bundle-href]


Version published
Weekly downloads
505K
decreased by-18.51%
Maintainers
2
Weekly downloads
 
Created
Source

untyped

npm version npm downloads Github Actions Codecov bundle

▶️ Check online playground

Usage

Install package

Install untyped npm package:

yarn add untyped
# or
npm i untyped

Define reference object

First we have to define a reference object that describes types, defaults and normalizer

const defaultPlanet = {
  name: 'earth',
  specs: {
    gravity: {
      $resolve: val => parseFloat(val),
      $default: '9.8'
    },
    moons: {
      $resolve: (val = ['moon']) => [].concat(val),
      $schema: {
        title: 'planet moons'
      }
    }
  }
}

Resolving Schema

import { resolveSchema } from 'untyped'

const schema = resolveSchema(defaultPlanet)

Output:

{
  "properties": {
    "name": {
      "type": "string",
      "default": "earth"
    },
    "specs": {
      "properties": {
        "gravity": {
          "default": 9.8,
          "type": "number"
        },
        "moons": {
          "title": "planet moons",
          "default": [
            "moon"
          ],
          "type": "array",
          "items": [
            {
              "type": "string"
            }
          ]
        }
      },
      "type": "object"
    }
  },
  "type": "object"
}

Generating types

import { resolveSchema, generateTypes } from 'untyped'

const types = generateTypes(resolveSchema(defaultPlanet))

Output:

interface Untyped {
   /** @default "earth" */
  name: string,

  specs: {
    /** @default 9.8 */
    gravity: number,

    /**
     * planet moons
     * @default ["moon"]
    */
    moons: string[],
  },
}

Generating markdown

import { resolveSchema, generateTypes, generateMarkdown } from 'untyped'

const markdown = generateMarkdown(generateTypes(resolveSchema(defaultPlanet)))

Output:

# `name`
- **Type**: `string`
- **Default**: `"earth"`


# `specs`

## `gravity`
- **Type**: `number`
- **Default**: `9.8`


## `moons`
- **Type**: `array`
- **Default**: `["moon"]`

Contribution

  • Clone repository
  • Install dependencies with yarn install
  • Use yarn dev to start playground (work with src/)
  • Use yarn test before push to ensure all tests and lint checks passing

License

MIT

Thanks to @dominikschreiber for donating package name.

FAQs

Package last updated on 10 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc